package data_store

import (
	"zxs-micro-2/zxs-micro-balance-server/utils"
)

type BalanceData struct {
	ServerId      string
	ServerType    string
	ServerLoad    float64
	HeartBeatTime int64
}

func (b *BalanceData) ToChoice() utils.Choice {
	return utils.Choice{
		Item:   b.ServerId,
		Weight: uint(1000000 / b.ServerLoad),
	}
}

type DataStoreInterface interface {
	AddService(*BalanceData)
	ServerHeartBeat(*BalanceData)
	GetByIds([]string) []*BalanceData
	GetByType(string) []*BalanceData
}

var st map[string]DataStoreInterface

func init() {
	st = make(map[string]DataStoreInterface)
}

//暂时只有local的，所以先这么用着吧
func GenerateDataStoreStruct(types string, inputIntf DataStoreInterface) {
	st[types] = inputIntf
}

func GetDataStoreStruct(types string) DataStoreInterface {
	return st[types]
}
